﻿Public Class ControlAlumno
    Dim _acceso As New AccesoBD

    Private Sub buscarAlumnoLegajo(ByVal legajo As Integer)
        Dim consulta As String
        Dim tabla As New DataTable

        consulta = "select apellido + ', ' + nombre from alumnos where legajoAlumno = " & legajo
        tabla = _acceso.ejecutaSQL(consulta)
        Me.txtAlumno.Text = tabla.Rows(0)(0)
    End Sub

    Private Sub buscarAlumno(ByVal consulta As String)
        Dim aux As String
        Dim tabla As New DataTable

        aux = "select legajoAlumno, nombre + ', ' + apellido as nombre from alumnos where nombre like '" & consulta & "'" & " or apellido like '" & consulta & "'"
        tabla = _acceso.ejecutaSQL(aux)
        _acceso.load_combo(Me.cmbAlumno, tabla, "legajoAlumno", "nombre")
        Me.cmbAlumno.BringToFront()
    End Sub

    Private Sub btnBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscar.Click
        If Not String.IsNullOrWhiteSpace(Me.txtBuscaAlumno.Text) Then
            buscarAlumnoLegajo(Me.txtBuscaAlumno.Text)
        End If
    End Sub

    Private Sub txtBuscaAlumno_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtBuscaAlumno.KeyPress
        If Char.IsLetter(e.KeyChar) Then
            Dim data As New InputData
            data._dato = e.KeyChar
            data.ShowDialog()
            Me.buscarAlumno(data._dato)
            e.KeyChar = ""
        End If
    End Sub
End Class
